package com.twotwoshop.service.goods.controller;

import com.twotwoshop.domin.common.dtos.ResponseResult;
import com.twotwoshop.domin.goods.pojo.ProductFavorite;
import com.twotwoshop.service.goods.service.ProductFavoriteService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 商品收藏功能
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/goods/collection")
@Slf4j
public class ProductFavoriteController {

    private final ProductFavoriteService productFavoriteService;


    /** 收藏商品
     *
     * @return
     */
    @PostMapping("/add")
    public ResponseResult addFavorite(@RequestBody ProductFavorite productFavorite) {

        log.info("商品的收藏");

        return productFavoriteService.addFavorite(productFavorite);
    }


    /** 取消收藏
     *
     * @return
     */
    @PostMapping("/cancel")
    public ResponseResult cancelFavorite(@RequestBody ProductFavorite productFavorite) {

        log.info("取消收藏");

        return productFavoriteService.cancelFavorite(productFavorite);
    }

    /** 检查收藏商品
     *
     * @return
     */
    @GetMapping("check/{id}")
    public ResponseResult checkFavorite(@PathVariable Long id) {

        log.info("商品的收藏和取消收藏");

        return productFavoriteService.checkFavorite(id);
    }


    /** 收藏商品查询
     *
     * @return
     */
    @GetMapping("/list")
    public ResponseResult selectFavorite() {

        log.info("用户收藏商品的查询");

        return productFavoriteService.selectFavorite();
    }

}
